package com.hbpu.schedule.dao.impl;

import com.hbpu.schedule.dao.BaseDao;
import com.hbpu.schedule.dao.SysUserDao;
import com.hbpu.schedule.pojo.SysUser;
import com.hbpu.schedule.util.JDBCUtil;

import java.util.List;

public class SysUserDaoImpl implements SysUserDao {
    private final BaseDao baseDao = new BaseDao();

    @Override
    public int addUser(SysUser sysUser) {
        String sql = "insert into sys_user (username,user_pwd) values (?,?)";
        return baseDao.baseUpdate(sql, sysUser.getUserName(), sysUser.getUserPwd());
    }

    @Override
    public SysUser selectUserByName(String username) {
        String sql = "select uid, username as userName, user_pwd as userPwd from sys_user where username = ?";
        List<SysUser> sysUser = baseDao.baseQuery(SysUser.class, sql, username);
        if (sysUser != null && !sysUser.isEmpty()) {
            return sysUser.get(0);
        } else {
            return null;
        }
    }

}
